package com.linzp.bishe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linzp.bishe.entity.Users;
import com.linzp.bishe.mapper.UsersMapper;
import com.linzp.bishe.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 林泽鹏
 * @since 2021-11-01
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

	@Autowired
	private UsersMapper usersMapper;

	/**
	 * @Description 分页查询信息返回
	 * @Param [currentPage, pageSize]
	 * @return java.util.List<com.linzp.bishe.entity.Users>
	 */
	@Override
	public List<Users> getUserInformation(int currentPage, int pageSize) {
		Page<Users> page = new Page<>(currentPage,pageSize);
		usersMapper.selectPage(page,null);
		return page.getRecords();
	}

	/**
	 * @Description 更新管理员的用户
	 * @Param [user]
	 * @return void
	 */
	@Override
	public void updateAdminUser(Users user) {
		usersMapper.updateById(user);
	}

	/**
	 * @Description 通过账户ID得到用户ID�
	 * @Param [id]
	 * @return java.lang.Integer
	 */
	@Override
	public Users getByAccountIDUserID(Integer id) {
		QueryWrapper<Users> wrapper = new QueryWrapper<>();
		wrapper.eq("account_ID",id);
		return usersMapper.selectOne(wrapper);
	}

	@Override
	public <T, K extends IService<T>> void updateName(K k, int id, String newName, boolean ok) {
		UpdateWrapper<T> wrapper  = new UpdateWrapper<>();
		wrapper.eq("user_id",id);
		if (ok){
			wrapper.set("input_people",newName);
		}else{
			wrapper.set("attendee",newName);
		}
		k.update(wrapper);
	}
}
